<!--
 * @Author: your name
 * @Date: 2021-08-31 18:07:53
 * @LastEditTime: 2021-09-01 09:00:12
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \vue-admin-template\src\components\ScreenFull\index.vue
-->
<template>
  <!-- 放置一个图标 -->
  <div>
    <svg-icon :icon-class="isFullscreen ? 'exit-fullscreen' : 'fullscreen'" class="fullscreen" @click="toggleFull" />
  </div>
</template>
<script>
import screenfull from 'screenfull'
export default {
  name: 'ScreenFull',
  data() {
    return {
      isFullscreen: false // 是否是全屏
    }
  },
  mounted() {
    // change 监听全屏与否的状态
    screenfull.on('change', () => {
      // 插件本身给提供的，全屏与否的状态
      // 如果是全屏，值为 true，如果退出全屏，值为 false
      // console.log(screenfull.isFullscreen)
      this.isFullscreen = screenfull.isFullscreen
    })
  },
  methods: {
    toggleFull() {
      // toggle 方法是 screenfull 提供的切换到全屏的方法
      screenfull.toggle()

      this.isFullscreen = !this.isFullscreen
    }
  }
}
</script>
<style scoped lang="scss">

.fullscreen {
  width: 20px;
  height: 20px;
  color: #fff;
  cursor: pointer;
}
</style>
